package com.wlz.jvm;

import sun.misc.Launcher;

import java.net.URL;

/**
 *  类加载器示例
 *
 */
public class TestJDKClassLoader {

    public static void main(String[] args) {
        System.out.println(String.class.getClassLoader());  // 引导类加载器 （由于引导类加载器是c++实现 所以为null ）
        System.out.println(com.sun.crypto.provider.DESedeKeyFactory.class.getClassLoader().getClass().getName());  // 扩展类加载 sun.misc.Launcher$ExtClassLoader
        System.out.println(TestJDKClassLoader.class.getClassLoader().getClass().getName());   // 应用类加载 sun.misc.Launcher$AppClassLoader

        System.out.println();

        ClassLoader appclassloader = ClassLoader.getSystemClassLoader();
        ClassLoader extclassloader = appclassloader.getParent();
        ClassLoader bootstrapclassloader = extclassloader.getParent();

        System.out.println("bootstrapclassloader:   " + bootstrapclassloader);
        System.out.println("extclassloader:   " + extclassloader);
        System.out.println("appclassloader:   " + appclassloader);

        System.out.println();

        System.out.println("bootstrapclassloader 加载以下文件： ");
        URL[] urls = Launcher.getBootstrapClassPath().getURLs();
        for (int i = 0; i < urls.length; i++) {
            System.out.println(urls[i]);
        }

        System.out.println();
        System.out.println("extclassloader 加载以下文件： ");
        System.out.println(System.getProperty("java.ext.dirs"));


        System.out.println();
        System.out.println("appclassloader 加载以下文件： ");
        System.out.println(System.getProperty("java.class.path"));

    }

}
